#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul  6 15:58:04 2023

@author: liqingsimac
"""
import numpy as np
t=np.linspace(start=1790,stop=2000,num=22,endpoint=True)
x=np.array([3.9, 5.3, 7.2, 9.6, 12.9, 17.1, 23.2, 31.4, 
            38.6, 50.2, 62.9, 76.0, 92.0, 106.5, 123.2, 131.7,
            150.7, 179.3, 204.0, 226.5, 251.4, 281.4])

import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(t,x,'o')
ax.set_xlabel('year')
ax.set_ylabel('millions people ')
fig.savefig('us-population.png')

xx=x[0:-1] 
xx=xx.reshape((21,1))
aa=np.ones_like(xx)
A=np.hstack((aa,-xx))

B=np.diff(x)/x[0:-1]/10
B=B.reshape((21,1))
rb=np.dot(np.linalg.inv(np.dot(A.T,A)),np.dot(A.T,B))

